//
//  ActivityVC.m
//  Movie
//
//  Created by huazi on 15/11/2.
//  Copyright © 2015年 huazi. All rights reserved.
//

#import "ActivityVC.h"
#import "ADDetailViewController.h"
#import "HomePageAdCell.h"
#import "ActivityCategoryCell.h"
#import "ActivityMovieCell.h"
@interface ActivityVC ()
@property (strong, nonatomic)NSArray *arrayAds;//广告数组
@property (strong, nonatomic)NSArray *arrayCategorys; //分类的数组
@end

@implementation ActivityVC
- (void)setData {
    self.title =@"活动";
    self.arrayAds =[[NSMutableArray alloc] initWithObjects:@"",@"",@"", nil];
    self.arrayCategorys =[[NSMutableArray alloc] initWithObjects:[NSDictionary dictionaryWithObjectsAndKeys:@"a_qiangpiao",@"picUrl",@"抢票专区",@"name", nil],[NSDictionary dictionaryWithObjectsAndKeys:@"a_tucao",@"picUrl",@"影评吐槽",@"name", nil],[NSDictionary dictionaryWithObjectsAndKeys:@"a_aishangxiu",@"picUrl",@"爱上秀",@"name", nil],[NSDictionary dictionaryWithObjectsAndKeys:@"a_huodong",@"picUrl",@"活动汇总",@"name", nil], nil];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    [self setSubviews];
    [self setHTTPTest];
    // Do any additional setup after loading the view.
}
- (void)setSubviews {
    self.table =[[UITableView alloc] initWithFrame:CGRectMake(0, 0, DeviceWidth, DeviceHeight-64.0-49.0)];
    self.table.delegate =self;
    self.table.dataSource =self;
    self.table.separatorStyle =UITableViewCellSeparatorStyleNone;
    [self.table registerClass:[HomePageAdCell class] forCellReuseIdentifier:[HomePageAdCell cellIdentifier]];
    [self.table registerClass:[ActivityCategoryCell class] forCellReuseIdentifier:[ActivityCategoryCell cellIdentifier]];
    [self.table registerClass:[ActivityMovieCell class] forCellReuseIdentifier:[ActivityMovieCell cellIdentifier]];
    [self.view addSubview:self.table];
    //    [self addRefreshHeaderAndFooterView:self.table];
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.row ==0) {
        return kScaleDeviceLength(180.0);
    }
    if (indexPath.row ==1) {
        return 100.0;
    }
    return 130.0f;  //影票
    return kScaleDeviceLength(100.0);;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 7;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    //广告
    if (indexPath.row ==0) {
        HomePageAdCell *cell =[tableView dequeueReusableCellWithIdentifier:[HomePageAdCell cellIdentifier]];
        id model =self.arrayAds;
        cell.block =^(id model){
            ADDetailViewController *ad =[[ADDetailViewController alloc] init];
            ad.titleStr =@"广告";
            //            [model objectForKey:@"title"];
            ad.web_url =@"http://www.baidu.com";
            //            [model objectForKey:@"url"];
            [self HZPushTo:ad];
        };
        cell.selectionStyle =UITableViewCellSelectionStyleNone;
        [cell setDataCell:model];
        return cell;
        
    }
    if (indexPath.row ==1) {
        ActivityCategoryCell *cell =[tableView dequeueReusableCellWithIdentifier:[ActivityCategoryCell cellIdentifier]];
        id model =self.arrayCategorys;
        cell.selectionStyle =UITableViewCellSelectionStyleNone;
        [cell setDataCell:model];
        return cell;
    }

        ActivityMovieCell *cell =[tableView dequeueReusableCellWithIdentifier:[ActivityMovieCell cellIdentifier]];
        [cell setDataCell:nil];
        return cell;
    return nil;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
//    if (indexPath.row >0) {
//   
//    }
}

- (void)setHTTPTest {
    [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    NSDictionary *dicParams =@{};  //请求需要的参数
    HZMRequest *request =[[HZMRequest alloc] init];
    request.requsetId =kASXcompare;
    request.requestParamDic =dicParams;
    request.callBackDelegate =self;
    [[HZMAPImanager shareMAPImanager] getWithWSRequest:request];   //get  or Post
}
#pragma mark--HZMAPIManagerDelegate
- (void)transactionFinished:(HZMResponse *)response
{
    [MBProgressHUD hideHUDForView:self.view animated:YES];
    
    if ([response.requestId isEqualToString:kASXcompare])
    {
        DLog(@"%@",response.responseData);
    }
    else {
        [self.view makeToast:response.responseMsg duration:1.0 position:@"center"];
    }
  
}
- (void)transactionFailed:(HZMResponse *)response
{
    [MBProgressHUD hideHUDForView:self.view animated:YES];
    [self.view makeToast:response.responseMsg duration:1.0 position:@"center"];
}
@end
